<?php
//后台文章管理控制器
class ArticleController extends platformController {
	//文章首页动作
	public function indexAction() {
		//输出视图
		$this->display('index.html');
	}
	//展示添加文章的表单
	public function addAction() {
		$category = factory::M('categoryModel');
		$cateInfo = $category->getCategory();
		//分配变量
		$this->assign('cateInfo',$cateInfo);
		//输出视图文件
		$this->display('add.html');
	}
	//dealAdd动作
		public function dealAddAction() {
		//1,接收表单
		$art = array();
		$art['cate_id'] = $_POST['cate_id'];
		$art['title'] = $this->escapeData($_POST['title']);
		$art['author'] = $this->escapeData($_POST['author']);
		$art['art_desc'] = $this->escapeData($_POST['art_desc']);
		$art['content'] = $this->escapeData($_POST['content']);
		//2,判断数据的合法性
		if(empty($art['title']) || empty($art['author']) ||empty($art['art_desc']) || empty($art['content'])) {
			$this->jump('index.php?p=Back&c=Article&a=add',':( 填写的信息不完整!');
		}
		//判断该是否有缩略图上传,暂时省略
		//3,数据库入库,操作模型
		$category = factory::M('CategoryModel');
		//调用insertCate方法
		$result = $article->insertArt($art);
		//4,跳转分类首页
		if($result) {
			$this->jump('index.php?p=Back&c=Article&a=index');
		}else {
			$this->jump('index.php?p=Back&c=Article&a=add',':( 发生未知错误,发布失败!');
		}
	}
}